﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET.Monitor.DAL
{
    /// <summary>
    /// 工作票相关
    /// </summary>
    public class OperationTicketDAL
    {
        string strSql = "", strErrMsg = "";
        DataTable dt = new DataTable();

        InvokeWebService iw = new InvokeWebService();
        string rtdbRelationAddress = "";
        string rtdbRealTimeAddress = "";
        string rtdbNameSpace = "";
        public OperationTicketDAL()
        {
            rtdbRelationAddress = ConfigurationManager.ConnectionStrings["RelationURL"].ConnectionString;
            rtdbRealTimeAddress = ConfigurationManager.ConnectionStrings["RealTimeURL"].ConnectionString;
            rtdbNameSpace = ConfigurationManager.ConnectionStrings["NameSpace"].ConnectionString;
        }

        #region 新增工作票
        /// <summary>
        /// 新增工作票
        /// 创    建：刘重阳  
        /// 日    期：20150112 
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="taskContent"></param>
        /// <param name="dateTime"></param>
        /// <param name="stationId"></param>
        /// <returns></returns>
        public bool AddOperationTicketModel(string userId, string taskContent, string dateTime, string stationId, string ownerId)
        {
            strSql = "INSERT INTO T_INFO_INTERVENTION (T_USERID,T_TASK,I_FLAG,T_TIME,T_ORGID,T_OWNERID) VALUES('" + userId + "','" + taskContent + "',0,'" + dateTime + "','" + stationId + "','" + ownerId + "')";
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion

        #region 删除工作票
        /// <summary>
        /// 删除工作票
        /// 创    建：刘重阳  
        /// 日    期：20150112 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteOperationTicketModel(string id)
        {
            strSql = "DELETE FROM T_INFO_INTERVENTION WHERE ID_KEY=" + id;
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion

        #region 修改工作票
        /// <summary>
        /// 修改工作票
        /// 创    建：刘重阳  
        /// 日    期：20150112 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userId"></param>
        /// <param name="taskContent"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public bool UpdateOperationTicketModel(string id, string userId, string taskContent, string dateTime)
        {
            strSql = "UPDATE T_INFO_INTERVENTION SET T_USERID='" + userId + "',T_TASK='" + taskContent + "',T_TIME='" + dateTime + "' WHERE ID_KEY=" + id;
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion

        #region 工作票反馈
        /// <summary>
        /// 工作票反馈
        /// 创    建：刘重阳  
        /// 日    期：20150112 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="performance"></param>
        /// <returns></returns>
        public bool FeedbackTask(string id, string state, string performance)
        {
            strSql = "UPDATE T_INFO_INTERVENTION SET T_PERFORMANCE='" + performance + "',I_FLAG=" + state + " WHERE ID_KEY=" + id;
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion

        #region 根据Id查询task
        public DataTable GetTask(string id)
        {
            strSql = "SELECT * FROM T_INFO_INTERVENTION WHERE ID_KEY="+id;
            return (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
        }
        #endregion
    }
}
